package com.foodplus.www.adapter.home;

import android.content.Context;
import android.content.Intent;
import android.support.v4.app.FragmentActivity;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.foodplus.www.adapter.shop.ShopAdapter;
import com.foodplus.www.bean.home.GoodsSpecialListBean;
import com.foodplus.www.foodplus.R;
import com.foodplus.www.view.activity.GoodActivity;
import com.foodplus.www.view.activity.SipGoodActivity;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/11/1 0001.
 */

public class HomeChildAdapter extends RecyclerView.Adapter<HomeChildAdapter.HomeChildViewHolder> implements View.OnClickListener{

    private List<GoodsSpecialListBean> goodsData;
    private Context context;

    public HomeChildAdapter(List<GoodsSpecialListBean> goodsData, Context context) {
        this.goodsData = goodsData;
        this.context = context;
    }

    @Override
    public HomeChildViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_home_child_layout, parent, false);
        HomeChildViewHolder childViewHolder = new HomeChildViewHolder(view);

        return childViewHolder;
    }

    @Override
    public void onBindViewHolder(HomeChildViewHolder holder, int position) {
        Glide.with(context).load(goodsData.get(position).getGoods_img()).placeholder(R.mipmap.bg_morentu).fitCenter().into(holder.homeChildImage);
        holder.homeName.setText(goodsData.get(position).getGoods_name());
        holder.homeChildPrice.setText("￥"+goodsData.get(position).getGoods_price());
        String goods_id = goodsData.get(position).getGoods_id();
        holder.view.setTag(goods_id);
        holder.view.setOnClickListener(this);
    }

    @Override
    public int getItemCount() {

        return goodsData == null? 0 : goodsData.size();
    }

    @Override
    public void onClick(View view) {
        String tag = (String) view.getTag();
        Intent intent = new Intent(context, SipGoodActivity.class);
        intent.putExtra("id", tag);
        context.startActivity(intent);
        ((FragmentActivity)context).overridePendingTransition(R.anim.shop_trans_enter, 0);
    }

    public class HomeChildViewHolder extends RecyclerView.ViewHolder {
        View view;

        @BindView(R.id.home_child_image)
        ImageView homeChildImage;
        @BindView(R.id.home_name)
        TextView homeName;
        @BindView(R.id.home_child_price)
        TextView homeChildPrice;
        public HomeChildViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
            this.view = itemView;
        }
    }


}
